*------------------------------------------------------------------------------
* (1) Aggregatbetrachtungen 
*  Stimmenverteilungen B/L
*------------------------------------------------------------------------------

foreach wave of numlist 5/8 {
capture clonevar vote_nds_`wave' = kp`wave'_3197b 
capture clonevar vote_btw_`wave' = wabsfull_hyp`wave' 
recode vote_btw_`wave' (8888=.b) (9999=.t)
}

foreach wave of numlist 9 {
capture clonevar vote_nds_`wave' = kp`wave'_3198b 
capture clonevar vote_btw_`wave' = wabsfull`wave'
recode vote_btw_`wave' (8888=.b) (9999=.t)
}

recode vote_btw_8 (151 180 206 209 237 = 801)


putexcel set "tables\aggregate_attitude_development.xlsx", sheet(vote) replace

putexcel A2 = "NDS: Wahlabsicht W5"
putexcel A3 = "NDS: Wahlabsicht W6"
putexcel A4 = "NDS: Wahlabsicht W7"
putexcel A5 = "NDS: Wahlabsicht W8"
putexcel A6 = "NDS: Wahlverhalten W9"
putexcel A7 = "BTW: Wahlabsicht W5"
putexcel A8 = "BTW: Wahlabsicht W6"
putexcel A9 = "BTW: Wahlabsicht W7"
putexcel A10 = "BTW: Wahlverhalten W8"
putexcel A11 = "BTW: Wahlabsicht  W9"

//Columns
putexcel B1 = "CDU"
putexcel C1 = "SPD"
putexcel D1 = "FDP"
putexcel E1 = "Grüne"
putexcel F1 = "Linke"
putexcel G1 = "AfD"
putexcel H1 = "Andere"
putexcel I1 = "N"		


//Formatting
putexcel A1:A11, right border(right) overwritefmt
putexcel A1:I1, hcenter bold border(bottom) overwritefmt
putexcel I1:I11, hcenter bold border(left, double) 



local zeile 1
foreach var in vote_nds_ vote_btw_	{
		foreach wave of numlist 5/9 {
		local zeile = `zeile'+1
		
		fre `var'`wave'	
		
		putexcel B`zeile' = matrix(r(valid)'/r(N_valid)), nformat(percent)  
		putexcel I`zeile' = `r(N_valid)'
	}
}




